package com.spukmk3me.impl.libgdx;

import java.io.IOException;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.audio.Music;
import com.spukmk3me.debug.Logger;
import com.spukmk3me.io.FileHandle;
import com.spukmk3me.sound.Sound;

final class LibgdxMusic extends Sound
{
    @Override
    protected int _load() throws IOException
    {
        LibgdxFileHandle file = (LibgdxFileHandle)getFileHandle();
        
        /* $if SPUKMK3ME_DEBUG$ */
        Logger.log( "Loading music " + file.getPath() + "..." );
        /* $endif$ */
        
        m_gdxMusic = Gdx.audio.newMusic( file.m_handle );
        
        /* $if SPUKMK3ME_DEBUG$ */
        Logger.log( "done\n" );
        /* $endif$ */
        
        return 0;
    }

    @Override
    protected void _release()
    {
        m_gdxMusic.dispose();
        m_gdxMusic = null;
    }
    
    Music getMusic()
    {
        return m_gdxMusic;
    }
    
    private Music m_gdxMusic;
}
